home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / BYTEXOR.PRG < prev    next >
Text File  |  1991-08-16  |  3KB  |  87 lines

  1. /*
  2.  * File......: BYTEXOR.PRG
  3.  * Author....: Forest Belt, Computer Diagnostic Services, Inc.
  4.  * Date......: $Date:   16 Aug 1991 19:35:48  $
  5.  * Revision..: $Revision:   1.3  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/bytexor.prv  $
  7.  * 
  8.  * This is an original work by Forest Belt and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/bytexor.prv  $
  15.  * 
  16.  *    Rev 1.3   16 Aug 1991 19:35:48   GLENN
  17.  * Don Caton corrected some spelling errors in doc
  18.  * 
  19.  *    Rev 1.2   15 Aug 1991 23:03:10   GLENN
  20.  * Forest Belt proofread/edited/cleaned up doc
  21.  * 
  22.  *    Rev 1.1   14 Jun 1991 19:51:18   GLENN
  23.  * Minor edit to file header
  24.  * 
  25.  *    Rev 1.0   01 Apr 1991 01:00:58   GLENN
  26.  * Nanforum Toolkit
  27.  *
  28.  */
  29.  
  30.  
  31. /*  $DOC$
  32.  *  $FUNCNAME$
  33.  *     FT_BYTEXOR()
  34.  *  $CATEGORY$
  35.  *     String
  36.  *  $ONELINER$
  37.  *     Perform bit-wise XOR on two ASCII characters (bytes)
  38.  *  $SYNTAX$
  39.  *     FT_BYTEXOR( <cByte1>, <cByte2> ) -> cNewByte
  40.  *  $ARGUMENTS$
  41.  *     <cByte1> and <cByte2> are characters from CHR(0) to CHR(255).
  42.  *     May be passed in CHR() form, as character literals, or
  43.  *     as expressions evaluating to CHR() values.
  44.  *  $RETURNS$
  45.  *     Returns resulting byte, in CHR() form.  If parameters are faulty,
  46.  *     returns NIL.
  47.  *  $DESCRIPTION$
  48.  *     Can be used for bit-wise byte manipulation.  In effect, this is a
  49.  *     bit-by-bit XOR operation.  Equivalent to XOR assembler instruction.
  50.  *
  51.  *     This function is presented to illustrate that bit-wise operations
  52.  *     are possible with Clipper code.  For greater speed, write .C or
  53.  *     .ASM versions and use the Clipper Extend system.
  54.  *  $EXAMPLES$
  55.  *     This code performs a bit-wise XOR on two bytes represented
  56.  *     by CHR(32) and CHR(55):
  57.  *
  58.  *          cNewByte := FT_BYTEXOR( CHR(32), CHR(55) )
  59.  *          ? ASC( cNewByte )     // result: 23
  60.  *          ? cNewByte            // result: non-printable character
  61.  *
  62.  *     For a demonstration of Clipper bit manipulations, compile and
  63.  *     link the program BITTEST.PRG in the Nanforum Toolkit source code.
  64.  *  $SEEALSO$
  65.  *     FT_BYTEOR() FT_BYTENOT() FT_BYTENEG() FT_BYTEAND()
  66.  *  $END$
  67.  */
  68.  
  69. FUNCTION FT_BYTEXOR(cByte1, cByte2)
  70.  
  71.   LOCAL nCounter, cNewByte
  72.  
  73.   IF valtype(cByte1) != "C" .or. valtype(cByte2) != "C" // parameter check
  74.      cNewByte := NIL
  75.   ELSE
  76.      cNewByte := chr(0)
  77.      FOR nCounter := 0 to 7           // test each bit position
  78.         IF FT_ISBIT(cByte1, nCounter) .or. FT_ISBIT(cByte2, nCounter)
  79.            IF .not. (FT_ISBIT(cByte1, nCounter) .and. FT_ISBIT(cByte2, nCounter))
  80.               cNewByte := FT_BITSET(cNewByte, nCounter)
  81.            ENDIF
  82.         ENDIF
  83.      NEXT
  84.   ENDIF
  85.  
  86. RETURN cNewByte
  87.